﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Core.Component;

namespace Components
{
    public class SGVTabControl:TabControl, ISGVControl
    {
        public SGVTabControl()
            : base()
        {
            
        }

        public Core.Component.UIComponent component
        {
            set;
            get;
        }

        public string SGVTag
        {
            get;
            set;
        }

        public string SGVShortcutString
        {
            get;
            set;
        }

        public void RegisterModule(Core.Base.BaseModule module)
        {
            
        }

        public void UpdateFormat()
        {
        }

        public void Init()
        {
            SizeMode = TabSizeMode.FillToRight;
            TabStop = false;
        }

        public UIComponent Serialize()
        {
            UIComponent component = new UIComponent();
            SGVControlHelper.CreateUIComponentFromControl(component, this);

            if (component != null)
            {
                component.Value = this.Text;

                foreach (TabPage tabPage in this.TabPages)
                {
                    UIComponent tabPageComponent = new UIComponent();
                    SGVControlHelper.CreateUIComponentFromControl(tabPageComponent, tabPage);
                    tabPageComponent.Value = tabPage.Text;
                    foreach (Control ChildControl in tabPage.Controls)
                    {
                        if (ChildControl is ISGVControl)
                        {
                            UIComponent childComponent = ((ISGVControl)ChildControl).Serialize();
                            if (childComponent != null)
                                tabPageComponent.lstChilds.Add(childComponent);
                        }
                    }

                    component.lstChilds.Add(tabPageComponent);
                }
            }
            return component;
        }

        public void Deserialize(UIComponent component)
        {
            throw new NotImplementedException();
        }
    }
}
